import { reactive, watch } from 'vue';
import {
	MemberPageNameEnum, OpenDistributionEnum, OpenAgentEnum,
	ShowAgentPortalEnum, ShowInviterEnum, ShowStoresSwitchEnum,
	ShowServicePackageEnum, ShowCouponEnum, ShowPinTuanEnum, ShowSeckillEnum,
	ShowGroupBuyingEnum, ShowSolitaireEnum, ShowCalendarEnum, ShowCustomFormEnum,
	ShowInvoiceEnum,
	OrderTabStatusEnum
} from '@/core/enum';
import { useShopConfigStore } from '@/core/store';
import type { MemberOrderType, MemberServiceType, ShopConfigType } from '@/core/models';


export const useNavHook = () => {
	const shopConfigStore = useShopConfigStore();

	const navState = reactive<{
		orderList : Array<MemberOrderType>;
		myServiceList : Array<MemberServiceType>;
		incrementServiceList : Array<MemberServiceType>;
		otherServiceList : Array<MemberServiceType>;

	}>({
		orderList: [
			{
				name: '全部',
				img: "/static/images/member/order-icon-01.png",
				orderStatus: OrderTabStatusEnum.all,
			}, {
				name: '待付款',
				img: "/static/images/member/order-icon-02.png",
				orderStatus: OrderTabStatusEnum.pendingPayment,
			}, {
				name: '待发货',
				img: "/static/images/member/order-icon-03.png",
				orderStatus: OrderTabStatusEnum.pendingShipment,
			}, {
				name: '待收货',
				img: "/static/images/member/order-icon-04.png",
				orderStatus: OrderTabStatusEnum.pendingReceipt,
			}, {
				name: '待评价',
				img: "/static/images/member/order-icon-05.png",
				orderStatus: OrderTabStatusEnum.pendingEvaluated,
			},
		],
		myServiceList: [],
		incrementServiceList: [],
		otherServiceList: [],
	})

	const getMyServiceList = (config : ShopConfigType) => {
		return [
			{
				title: '分销中心',
				img: "/static/images/member/icon-distribution.png",
				name: MemberPageNameEnum.distribution,
				isShow: config?.openDistribution === OpenDistributionEnum.yes,
				url: "/pages/subpackage/distribution/apply/index"
			}, {
				title: '代理中心',
				img: "/static/images/member/icon-agent.png",
				name: MemberPageNameEnum.agent,
				isShow: config?.isOpenAgent === OpenAgentEnum.yes && config?.isShowAgentPortal === ShowAgentPortalEnum.yes,
				url: "/pages/subpackage/agency/apply/index"
			}, {
				title: '我的优惠券',
				img: "/static/images/member/icon-coupon.png",
				name: MemberPageNameEnum.myCoupon,
				isShow: config?.showCoupon === ShowCouponEnum.yes,
				url: "/pages/subpackage/member/coupon/coupon"
			}, {
				title: '我的余额',
				img: "/static/images/member/icon-balance.png",
				name: MemberPageNameEnum.balance,
				isShow: true,
				url: "/pages/subpackage/member/balance/index/index"
			}, {
				title: '我的发票',
				img: "/static/images/member/icon-invoice.png",
				name: MemberPageNameEnum.calendar,
				isShow: config?.invoiceSwitch === ShowInvoiceEnum.yes,
				url: "/pages/subpackage/member/invoice/invoice/invoice"
			}, {
				title: '我购买的服务',
				img: "/static/images/member/icon-service-card.png",
				name: MemberPageNameEnum.bell,
				isShow: config?.showServicePackage === ShowServicePackageEnum.yes,
				url: "/pages/subpackage/member/serviceOrder/list/list"
			}, {
				title: `我的${config?.pointShowName || '积分'}`,
				img: "/static/images/member/icon-integral.png",
				name: MemberPageNameEnum.integral,
				isShow: true,
				url: "/pages/subpackage/member/integral/integral"
			}, {
				title: '地址管理',
				img: "/static/images/member/icon-address.png",
				name: MemberPageNameEnum.address,
				isShow: true,
				url: "/pages/subpackage/member/address/list/list"
			}, {
				title: '我的收藏',
				img: "/static/images/member/icon-bookmark.png",
				name: MemberPageNameEnum.bookmark,
				isShow: true,
				url: "/pages/subpackage/member/collection/collection"
			}, {
				title: '我的足迹',
				img: "/static/images/member/icon-history.png",
				name: MemberPageNameEnum.history,
				isShow: true,
				url: "/pages/subpackage/member/footprint/footprint"
			}
		]
	}

	const getIncrementServiceList = (config : ShopConfigType) => {
		return [
			{
				title: '门店列表',
				img: "/static/images/member/icon-store.png",
				name: MemberPageNameEnum.storeList,
				isShow: config?.showStoresSwitch === ShowStoresSwitchEnum.yes,
				url: "/pages/subpackage/storeMap/storeMap"
			}, {
				title: '服务商品',
				img: "/static/images/member/icon-service-goods.png",
				name: MemberPageNameEnum.serviceGoods,
				isShow: config?.showServicePackage === ShowServicePackageEnum.yes,
				url: "/pages/subpackage/serviceGoods/list/list"
			}, {
				title: '优惠券',
				img: "/static/images/member/icon-coupon.png",
				name: MemberPageNameEnum.coupon,
				isShow: config?.showCoupon === ShowCouponEnum.yes,
				url: "/pages/subpackage/coupon/coupon"
			}, {
				title: '拼团',
				img: "/static/images/member/icon-pinTuan.png",
				name: MemberPageNameEnum.pinTuan,
				isShow: config?.showPinTuan === ShowPinTuanEnum.yes,
				url: "/pages/subpackage/activity/pinTuan/list/list"
			}, {
				title: '秒杀',
				img: "/static/images/member/icon-seckill.png",
				name: MemberPageNameEnum.seckill,
				isShow: config?.showSeckill === ShowSeckillEnum.yes,
				url: "/pages/subpackage/activity/seckill/list/list"
			}, {
				title: '团购',
				img: "/static/images/member/icon-groupBuying.png",
				name: MemberPageNameEnum.groupBuying,
				isShow: config?.showGroupBuying === ShowGroupBuyingEnum.yes,
				url: "/pages/subpackage/activity/groupBuying/list/list"
			}, {
				title: '接龙',
				img: "/static/images/member/icon-solitaire.png",
				name: MemberPageNameEnum.solitaire,
				isShow: config?.showSolitaire === ShowSolitaireEnum.yes,
				url: "/pages/subpackage/activity/solitaire/list/list"
			}, {
				title: '签到',
				img: "/static/images/member/icon-checkIn.png",
				name: MemberPageNameEnum.checkIn,
				isShow: config?.showCalendar === ShowCalendarEnum.yes,
				url: "/pages/subpackage/activity/checkIn/checkIn"
			}, {
				title: '万能表单',
				img: "/static/images/member/icon-form.png",
				name: MemberPageNameEnum.form,
				isShow: config?.showCustomForm === ShowCustomFormEnum.yes,
				url: "/pages/subpackage/form/list/list"
			}
		];
	}

	const getOtherServiceList = (config : ShopConfigType) => {
		return [
			{
				title: '通知公告',
				img: "/static/images/member/icon-notice.png",
				name: MemberPageNameEnum.notice,
				isShow: true,
				url: "/pages/subpackage/notice/list/list"
			}, {
				title: '文档中心',
				img: "/static/images/member/icon-help.png",
				name: MemberPageNameEnum.helpCenter,
				isShow: true,
				url: "/pages/subpackage/article/list/list"
			}, {
				title: '邀请好友',
				img: "/static/images/member/icon-invite.png",
				name: MemberPageNameEnum.invite,
				isShow: config?.showInviter === ShowInviterEnum.yes,
				url: "/pages/subpackage/member/invite/invite/invite"
			}, {
				title: '商品检索',
				img: "/static/images/member/icon-search.png",
				name: MemberPageNameEnum.search,
				isShow: true,
				url: "/pages/search/search"
			}, {
				title: '系统设置',
				img: "/static/images/member/icon-setting.png",
				name: MemberPageNameEnum.setting,
				isShow: true,
				url: "/pages/subpackage/member/set/index/index"
			}
		]
	}

	const hanldeServiceData = (config : ShopConfigType) => {
		navState.myServiceList = getMyServiceList(config);
		navState.incrementServiceList = getIncrementServiceList(config);
		navState.otherServiceList = getOtherServiceList(config);
	}

	const getNav = () => {
		watch(() => shopConfigStore.config, (newVal : ShopConfigType) => {
			hanldeServiceData(newVal);
		}, { immediate: true })
	}

	return { getNav, navState };
}